/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.c;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.login.plugin.a.h;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.h.f;

public class a extends SQLiteOpenHelper {
    private static final Object a = new Object();
    private static a b = null;
    private Context c;

    public static synchronized a a(Context paramContext) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "getInstance Entry!" });
        if (null == b)
            b = new a(paramContext, "com.qihoo.gamecenter.sdk.user", null, 1);
        return b;
    }

    private a(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt) {
        super(paramContext, paramString, paramCursorFactory, paramInt);
        this.c = paramContext;
    }

    public void onCreate(SQLiteDatabase paramSQLiteDatabase) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "onCreate Entry!" });
        paramSQLiteDatabase.execSQL("DROP TABLE IF EXISTS users");
        paramSQLiteDatabase
                .execSQL("CREATE TABLE users(account TEXT, token TEXT, qt TEXT, info TEXT, ext1 TEXT, ext2 TEXT, ext3 TEXT, ext4 TEXT, ext5 TEXT);");
    }

    public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2) {}

    public String a(String paramString) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "getUserInfo Entry! acc: " + paramString });
        synchronized (a) {
            String str = a("account", paramString, "info");
            str = e(str);
            return str;
        }
    }

    public String b(String paramString) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "getToken Entry! acc: " + paramString });
        synchronized (a) {
            String str = a("account", paramString, "token");
            str = e(str);
            return str;
        }
    }

    public String c(String paramString) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "getQtByAccount Entry! acc: " + paramString });
        if (h.b(this.c, paramString))
            return null;
        synchronized (a) {
            String str = a("account", paramString, "qt");
            str = e(str);
            return str;
        }
    }

    public void a(String paramString1, String paramString2, String paramString3, String paramString4) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "addUserInfo Entry!", " account = ", paramString1 });
        paramString2 = d(paramString2);
        paramString3 = d(paramString3);
        paramString4 = d(paramString4);
        synchronized (a) {
            String str = a("account", paramString1, "token");
            if (!(TextUtils.isEmpty(str)))
                a(paramString1, paramString2, paramString3, paramString4, "", "", "", "", "");
            else
                b(paramString1, paramString2, paramString3, paramString4, "", "", "", "", "");
        }
    }

    private String a(String paramString1, String paramString2, String paramString3) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "doQueryNoLock Entry!" });
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "key = " + paramString1 });
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "keyV = " + paramString2 });
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "query = " + paramString3 });
        String str = null;
        SQLiteDatabase localSQLiteDatabase = getReadableDatabase();
        Cursor localCursor = null;
        try {
            localCursor = localSQLiteDatabase.query("users", new String[] { paramString3 }, paramString1 + "=?",
                    new String[] { paramString2 }, null, null, null);
            if (localCursor != null) {
                e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "doquery count: " + localCursor.getCount() });
                if (localCursor.moveToFirst())
                    str = localCursor.getString(0);
            }
        } catch (Exception localException) {
            e.b("Plugin.db.UserTokenQTDBHelper", "getUserInfo Exception!", localException);
        } finally {
            if (localCursor != null) {
                localCursor.close();
                localCursor = null;
            }
            if (localSQLiteDatabase != null) {
                localSQLiteDatabase.close();
                localSQLiteDatabase = null;
            }
        }
        return str;
    }

    private boolean a(String paramString1, String paramString2, String paramString3, String paramString4,
            String paramString5, String paramString6, String paramString7, String paramString8, String paramString9) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "updateRaw Entry!" });
        SQLiteDatabase localSQLiteDatabase = getWritableDatabase();
        try {
            ContentValues localContentValues = new ContentValues();
            localContentValues.put("account", paramString1);
            localContentValues.put("token", paramString2);
            localContentValues.put("qt", paramString3);
            localContentValues.put("info", paramString4);
            localContentValues.put("ext1", paramString5);
            localContentValues.put("ext2", paramString6);
            localContentValues.put("ext3", paramString7);
            localContentValues.put("ext4", paramString8);
            localContentValues.put("ext5", paramString9);
            localSQLiteDatabase.update("users", localContentValues, "account=?", new String[] { paramString1 });
            return true;
        } catch (Exception localException) {
            e.b("Plugin.db.UserTokenQTDBHelper", "updateRaw Exception!", localException);
        }
        return false;
    }

    private boolean b(String paramString1, String paramString2, String paramString3, String paramString4,
            String paramString5, String paramString6, String paramString7, String paramString8, String paramString9) {
        e.a("Plugin.db.UserTokenQTDBHelper", new Object[] { "addNewRaw Entry!" });
        SQLiteDatabase localSQLiteDatabase = getWritableDatabase();
        try {
            ContentValues localContentValues = new ContentValues();
            localContentValues.put("account", paramString1);
            localContentValues.put("token", paramString2);
            localContentValues.put("qt", paramString3);
            localContentValues.put("info", paramString4);
            localContentValues.put("ext1", paramString5);
            localContentValues.put("ext2", paramString6);
            localContentValues.put("ext3", paramString7);
            localContentValues.put("ext4", paramString8);
            localContentValues.put("ext5", paramString9);
            localSQLiteDatabase.insert("users", "", localContentValues);
            return true;
        } catch (Exception localException) {
            e.b("Plugin.db.UserTokenQTDBHelper", "updateRaw Exception!", localException);
        }
        return false;
    }

    private String d(String paramString) {
        if (null == paramString)
            return null;
        return f.b(paramString, "[jk1f%v6");
    }

    private String e(String paramString) {
        if (null == paramString)
            return null;
        return f.c(paramString, "[jk1f%v6");
    }
}